﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace SteamGroupPlayers.View
{
    class SteamListBox : ListBox
    {
        /// <summary>
        /// pretty nasty hack, because it doesn't fix the error in any way shape or form . . it simply alleviates the effect.
        /// In case you wonder, what error: Size calculation returning infinity, due to dynamically sized items.
        /// </summary>
        /// <param name="constraint">-</param>
        /// <returns>-</returns>
        protected override System.Windows.Size MeasureOverride(Size constraint)
        {
            try
            {
                var baseSize = base.MeasureOverride(constraint);

                if (double.IsPositiveInfinity(baseSize.Width) || double.IsPositiveInfinity(baseSize.Height))
                    return Size.Empty;

                return baseSize;
            }
            catch (InvalidOperationException ioex)
            {
                return Size.Empty;
            }
            //return constraint;
        }
    }
}
